<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>仁爱宠物医院</title>
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  <script src="https://unpkg.com/vue@2/dist/vue.js"></script>
  <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  <script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
  <link href="https://cdn.staticfile.net/twitter-bootstrap/5.1.1/css/bootstrap.min.css" rel="stylesheet">
  <script src="https://cdn.staticfile.net/twitter-bootstrap/5.1.1/js/bootstrap.bundle.min.js"></script>
  <script src="https://cdn.staticfile.org/vue-resource/1.5.1/vue-resource.min.js"></script>
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<style>
  #register{
    width: 100%;
    height: 100vh;
    background: url('../img/resgister_bg.jfif') no-repeat;
    background-size: 100% 100%;
    overflow: hidden;
  }
</style>
<body>
  <div id="register">
    <div style="background-color: #fff; width: 25%; margin: auto; margin-top: 15%;padding: 3%;text-align: center;">
      <h3>管理员注册</h3><p></p><p></p>
      <form action="#" method="post">
        <label for="account">账号：</label><input type="text" v-model="user.account"><p></p>
        <label for="password">密码：</label><input type="password" v-model="user.password"><p></p>
        <label for="password">确认密码：</label><input type="password" v-model="pass"><p></p>
        <button type="button" style="border: 0; padding: 10px 20px;" @click="register()">注册</button><p></p>
      </form>
      <a href="./login.html">立即登录</a>
    </div>
  </div>
</body>
<script>
  new Vue({
    el: '#register',
    data() {
      return {
        pass: '',
        user: {
          account: '',
          password: '',
        }
      }
    },
    // 方法
    methods: {
      // 登录
      async register() {
        // 判断用户输入的两次密码是否是同一个密码
        if(this.user.password !== this.pass){
          this.$message.error("密码不一致，请重试输入密码？");
        }
        const {data : result} = await this.$http.post('http://localhost:8082/user_backend/register',this.user);
        if(result.flag){
          this.$message.success(result.message)
          // 跳转页面
          window.location.href = './login.html';
        }else{
          this.$message.error(result.message)
        }
      }
    }
  })
</script>
</html>